package com.delu.controller;

import com.delu.data.Result;
import com.delu.em.ResultEnum;
import com.delu.entity.Area;
import com.delu.entity.Site;
import com.delu.mapper.AreaSiteMapper;
import com.delu.mapper.SiteSiteMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.awt.*;
import java.util.List;

@RestController
@RequestMapping("area")
@Api("网点管理")
public class AreaController {
    @Resource
    private AreaSiteMapper areaSiteMapper;

    @Resource
    private SiteSiteMapper sitesiteMapper;

    @GetMapping
    @ApiOperation("网点区管理查询")
    @ApiImplicitParam(name = "id",value = "区网点ID",required = true,paramType = "query")
    public Result selectArea(@RequestParam("id")Integer id){
        System.out.println("区网点的查询" + id);
        List<Area> areaList = areaSiteMapper.selectArea(id);
        return Result.response(ResultEnum.SUCCESS).setData(areaList);
    }

    @PostMapping
    @ApiOperation("网点区管理增加")
    @ApiImplicitParam(name = "Site",value = "网点的实体类",required = true,paramType = "body")
    public Result insertArea(@RequestBody Site site){
        Integer i = sitesiteMapper.insert(site);
        System.out.println("网点信息" + site);
        return Result.response(ResultEnum.SUCCESS).setData(i);
    }

    @DeleteMapping
    @ApiOperation("区网点管理删除")
    @ApiImplicitParam(name = "siteId",value = "网点ID",required = true,paramType = "query")
    public Result deleteArea(@RequestParam("siteId")Long siteId){
        System.out.println("网点信息删除" + siteId);
        Integer i = sitesiteMapper.deleteById(siteId);
        return Result.response(ResultEnum.SUCCESS).setData(i);
    }

}
